package cn.gson.fengboot.controller;

import cn.gson.fengboot.model.pojos.Zreturnedmoney;
import cn.gson.fengboot.model.service.ZreturnedmoneyService;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ZreturnedmoneyController {
    @Autowired
    ZreturnedmoneyService hkservice;

    @RequestMapping("/hk_list")
    @ResponseBody
    public Map<String,Object> kaipiao(Integer page, Integer size,String search,String search2,String search3){
        Page<Object> obj = PageHelper.startPage(page, size);
        hkservice.hklist(search,search2,search3);

        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",obj.getResult());
        return map;
    }

    @RequestMapping("/hkjh_list")
    @ResponseBody
    public Map<String,Object> kajhipiao(Integer page, Integer size,String search,String search2){
        Page<Object> obj = PageHelper.startPage(page, size);
        hkservice.hkjhlist(search,search2);

        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",obj.getResult());
        return map;
    }

    @RequestMapping("/dd_hkjh")
    @ResponseBody
    public List<Zreturnedmoney> ddhkjh(String search){


        return hkservice.ddhkjh(search);
    }

    @RequestMapping("/dd_tkjh")
    @ResponseBody
    public List<Zreturnedmoney> ddtkjh(String search){
        return hkservice.ddtkjh(search);
    }

    @RequestMapping("/thd_tkjh")
    @ResponseBody
    public List<Zreturnedmoney> thddtkjh(String search){
        return hkservice.thdtkjh(search);
    }

    @RequestMapping("/delete_jh2")
    @ResponseBody
    public void sc2(@RequestBody Zreturnedmoney jh){
        hkservice.sc2(jh);
    }

    @RequestMapping("/add_jh")
    @ResponseBody
    public void add(String busfrom){
        System.out.println(busfrom);
        JSONObject obj = (JSONObject)JSONObject.parse(busfrom);
        Zreturnedmoney jh=obj.getObject("jh",Zreturnedmoney.class);
        System.out.println("2");
        Double yuanjg = obj.getObject("yuanjg", Double.class);
        System.out.println("3");
        hkservice.add(jh,yuanjg);
    }

    @RequestMapping("/clienthkjh-list")
    @ResponseBody
    public List<Zreturnedmoney> clienthkjh(String search){
        //客户id查询回款计划
        return hkservice.clienthkjh(search);
    }

}